package com.androidx.p013lv.player.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import com.androidx.p013lv.base.bean.AddTimesReq;
import com.androidx.p013lv.base.bean.PurVideoBean;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.utils.LogUtils;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.TimeUtils;
import com.androidx.p013lv.player.C1387R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.google.gson.Gson;
import p000a.shuyu.p005a.GSYVideoManager;
import p000a.shuyu.p005a.listener.GSYVideoProgressListener;
import p000a.shuyu.p005a.video.StandardGSYVideoPlayer;
import p000a.shuyu.p005a.video.base.GSYBaseVideoPlayer;

/* renamed from: com.androidx.lv.player.view.BrushVideoPlayer */
public class BrushVideoPlayer extends StandardGSYVideoPlayer implements GSYVideoProgressListener {
    int FreeTime = 4800;
    private boolean isShow;
    private ImageView ivImg;
    private ImageView ivType;
    private ImageView mCoverImage;
    private PlayerVideoInterface playerVideoInterface;
    private int position;
    LinearLayout root_pay;
    LinearLayout root_vip;
    private TextView totalTimes;
    private TextView tvTitle;
    private TextView tv_buy_perice;
    private TextView tv_lease_days;
    private TextView tv_lease_perice;
    private VideoBean videoBean;
    View view;

    /* renamed from: com.androidx.lv.player.view.BrushVideoPlayer$PlayerVideoInterface */
    public interface PlayerVideoInterface {
        void buyVideo(BrushVideoPlayer brushVideoPlayer, VideoBean videoBean, int i);

        void buyVip(BrushVideoPlayer brushVideoPlayer, VideoBean videoBean, int i);

        void click(BrushVideoPlayer brushVideoPlayer, VideoBean videoBean, int i, int i2);

        void leaseVideo(BrushVideoPlayer brushVideoPlayer, VideoBean videoBean, int i);
    }

    public void setVideoBean(VideoBean videoBean2, int i, PlayerVideoInterface playerVideoInterface2) {
        this.videoBean = videoBean2;
        this.position = i;
        this.playerVideoInterface = playerVideoInterface2;
        initVideoData();
    }

    public int getPosition() {
        return this.position;
    }

    public BrushVideoPlayer(Context context, Boolean bool) {
        super(context, bool);
    }

    public BrushVideoPlayer(Context context) {
        super(context);
    }

    public BrushVideoPlayer(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    @Override // p000a.shuyu.p005a.video.StandardGSYVideoPlayer, p000a.shuyu.p005a.video.base.GSYVideoView
    public int getLayoutId() {
        return C1387R.C1392layout.video_player_brush_layout;
    }

    /* access modifiers changed from: protected */
    @Override // p000a.shuyu.p005a.video.StandardGSYVideoPlayer, p000a.shuyu.p005a.video.base.GSYVideoControlView, p000a.shuyu.p005a.video.base.GSYBaseVideoPlayer, p000a.shuyu.p005a.video.base.GSYVideoView
    public void init(Context context) {
        super.init(context);
        this.ivImg = (ImageView) findViewById(C1387R.C1390id.iv_img);
        this.mCoverImage = (ImageView) findViewById(C1387R.C1390id.thumbImage);
        this.totalTimes = (TextView) findViewById(C1387R.C1390id.total_times);
        this.tvTitle = (TextView) findViewById(C1387R.C1390id.tv_title);
        this.ivType = (ImageView) findViewById(C1387R.C1390id.iv_type);
        this.tv_lease_days = (TextView) findViewById(C1387R.C1390id.tv_lease_days);
        this.tv_lease_perice = (TextView) findViewById(C1387R.C1390id.tv_lease_perice);
        this.tv_buy_perice = (TextView) findViewById(C1387R.C1390id.tv_buy_perice);
        ((TextView) findViewById(C1387R.C1390id.btn_buy_vip)).setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.player.view.BrushVideoPlayer.View$OnClickListenerC13961 */

            public void onClick(View view) {
                if (BrushVideoPlayer.this.playerVideoInterface != null) {
                    PlayerVideoInterface playerVideoInterface = BrushVideoPlayer.this.playerVideoInterface;
                    BrushVideoPlayer brushVideoPlayer = BrushVideoPlayer.this;
                    playerVideoInterface.buyVip(brushVideoPlayer, brushVideoPlayer.videoBean, BrushVideoPlayer.this.position);
                }
            }
        });
        ((LinearLayout) findViewById(C1387R.C1390id.player_btn_lease)).setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.player.view.BrushVideoPlayer.View$OnClickListenerC13972 */

            public void onClick(View view) {
                if (BrushVideoPlayer.this.playerVideoInterface != null) {
                    PlayerVideoInterface playerVideoInterface = BrushVideoPlayer.this.playerVideoInterface;
                    BrushVideoPlayer brushVideoPlayer = BrushVideoPlayer.this;
                    playerVideoInterface.leaseVideo(brushVideoPlayer, brushVideoPlayer.videoBean, BrushVideoPlayer.this.position);
                }
            }
        });
        ((LinearLayout) findViewById(C1387R.C1390id.player_btn_buy)).setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.player.view.BrushVideoPlayer.View$OnClickListenerC13983 */

            public void onClick(View view) {
                if (BrushVideoPlayer.this.playerVideoInterface != null) {
                    if (BrushVideoPlayer.this.getCurrentState() == 2) {
                        BrushVideoPlayer.this.onVideoPause();
                    }
                    PlayerVideoInterface playerVideoInterface = BrushVideoPlayer.this.playerVideoInterface;
                    BrushVideoPlayer brushVideoPlayer = BrushVideoPlayer.this;
                    playerVideoInterface.buyVideo(brushVideoPlayer, brushVideoPlayer.videoBean, BrushVideoPlayer.this.position);
                }
            }
        });
        if (this.mThumbImageViewLayout != null && (this.mCurrentState == -1 || this.mCurrentState == 0 || this.mCurrentState == 7)) {
            this.mThumbImageViewLayout.setVisibility(0);
        }
        this.root_pay = (LinearLayout) findViewById(C1387R.C1390id.root_pay);
        this.root_vip = (LinearLayout) findViewById(C1387R.C1390id.root_vip);
        this.root_pay.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.player.view.BrushVideoPlayer.View$OnClickListenerC13994 */

            public void onClick(View view) {
            }
        });
        this.root_vip.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.player.view.BrushVideoPlayer.View$OnClickListenerC14005 */

            public void onClick(View view) {
            }
        });
        View findViewById = findViewById(C1387R.C1390id.view_click);
        this.view = findViewById;
        findViewById.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.player.view.BrushVideoPlayer.View$OnClickListenerC14016 */

            public void onClick(View view) {
                if (BrushVideoPlayer.this.playerVideoInterface != null) {
                    PlayerVideoInterface playerVideoInterface = BrushVideoPlayer.this.playerVideoInterface;
                    BrushVideoPlayer brushVideoPlayer = BrushVideoPlayer.this;
                    playerVideoInterface.click(brushVideoPlayer, brushVideoPlayer.videoBean, BrushVideoPlayer.this.position, 1);
                    BrushVideoPlayer.this.startPlayLogic();
                }
            }
        });
        this.ivImg.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.player.view.BrushVideoPlayer.View$OnClickListenerC14027 */

            public void onClick(View view) {
                if (BrushVideoPlayer.this.playerVideoInterface != null) {
                    PlayerVideoInterface playerVideoInterface = BrushVideoPlayer.this.playerVideoInterface;
                    BrushVideoPlayer brushVideoPlayer = BrushVideoPlayer.this;
                    playerVideoInterface.click(brushVideoPlayer, brushVideoPlayer.videoBean, BrushVideoPlayer.this.position, 1);
                    if (BrushVideoPlayer.this.getCurrentState() != 2) {
                        BrushVideoPlayer.this.startPlayLogic();
                    }
                }
            }
        });
        setPlayPosition(this.position);
        if (this.mGSYVideoProgressListener == null) {
            setGSYVideoProgressListener(this);
        }
    }

    public ViewGroup getBottomContainer() {
        return this.mBottomContainer;
    }

    @Override // p000a.shuyu.p005a.video.StandardGSYVideoPlayer, p000a.shuyu.p005a.video.base.GSYBaseVideoPlayer
    public GSYBaseVideoPlayer startWindowFullscreen(Context context, boolean z, boolean z2) {
        GSYBaseVideoPlayer startWindowFullscreen = super.startWindowFullscreen(context, z, z2);
        if (startWindowFullscreen != null) {
            BrushVideoPlayer brushVideoPlayer = (BrushVideoPlayer) startWindowFullscreen;
            brushVideoPlayer.setVideoBean(getVideoBean());
            brushVideoPlayer.initTitle();
        }
        return startWindowFullscreen;
    }

    /* access modifiers changed from: protected */
    @Override // p000a.shuyu.p005a.video.StandardGSYVideoPlayer
    public void updateStartImage() {
        if (this.mStartButton instanceof ImageView) {
            ImageView imageView = (ImageView) this.mStartButton;
            if (this.mCurrentState == 2) {
                imageView.setImageResource(C1387R.C1389drawable.player_brush_video_pause);
                setViewShowState(this.view, 8);
            } else if (this.mCurrentState == 7) {
                imageView.setImageResource(C1387R.C1389drawable.player_brush_video_play);
                setViewShowState(this.view, 0);
            } else {
                imageView.setImageResource(C1387R.C1389drawable.player_brush_video_play);
                setViewShowState(this.view, 0);
            }
            this.isShow = false;
            this.root_vip.setVisibility(8);
            this.root_pay.setVisibility(8);
        }
    }

    @Override // p000a.shuyu.p005a.video.StandardGSYVideoPlayer, p000a.shuyu.p005a.video.base.GSYVideoView
    public void startPlayLogic() {
        if (this.videoBean.isAd() && this.videoBean.getAdInfoBean().getAdType().equals("IMG")) {
            GSYVideoManager.releaseAllVideos();
        } else if (!this.isShow) {
            super.startPlayLogic();
            if (this.videoBean.getVideoType() == 2 && !this.videoBean.isBuy() && !this.videoBean.isCanWatch()) {
                isPurVideo();
            }
        } else {
            GSYVideoManager.onPause();
        }
    }

    /* access modifiers changed from: protected */
    @Override // p000a.shuyu.p005a.video.StandardGSYVideoPlayer, p000a.shuyu.p005a.video.base.GSYVideoControlView
    public void showWifiDialog() {
        startPlayLogic();
    }

    public void setIsBuy(boolean z) {
        this.videoBean.setBuy(z);
        this.videoBean.setCanWatch(true);
        this.isShow = false;
        onVideoResume();
        this.root_pay.setVisibility(8);
    }

    @Override // p000a.shuyu.p005a.listener.GSYVideoProgressListener
    public void onProgress(int i, int i2, int i3, int i4) {
        if (!this.videoBean.isAd() && this.videoBean != null && i3 > this.FreeTime) {
            UserInfo userInfo = SpUtils.getInstance().getUserInfo();
            int freeWatches = userInfo.getFreeWatches() - userInfo.getWatched();
            if (!(userInfo.getFreeWatches() == -1 && (this.videoBean.getVideoType() == 0 || this.videoBean.getVideoType() == 1)) && ((this.videoBean.getVideoType() != 0 || freeWatches <= 0) && (this.videoBean.getVideoType() != 2 || !this.videoBean.isBuy()))) {
                if (this.videoBean.getVideoType() == 0 && freeWatches <= 0 && this.videoBean.isReport()) {
                    return;
                }
                if (isIfCurrentIsFullscreen()) {
                    clearFullscreenLayout();
                    return;
                }
                onVideoPause();
                this.mStartButton.setVisibility(8);
                this.isShow = true;
                if (this.videoBean.getVideoType() == 0 && freeWatches <= 0) {
                    this.root_vip.setVisibility(0);
                } else if (this.videoBean.getVideoType() == 1) {
                    this.root_vip.setVisibility(0);
                } else if (this.videoBean.getVideoType() == 2) {
                    this.root_pay.setVisibility(0);
                }
            } else if (!this.videoBean.isReport()) {
                this.videoBean.setReport(true);
                if (this.videoBean.getVideoType() == 0) {
                    userInfo.setWatched(userInfo.getWatched() + 1);
                    SpUtils.getInstance().setUserInfo(userInfo);
                }
                addStatisticsTimes(this.videoBean.getVideoType() + 1, 5, this.videoBean.getVideoId());
            }
        }
    }

    public void addStatisticsTimes(int i, int i2, int i3) {
        String addStatisticsTimes = UrlManager.getInsatance().addStatisticsTimes();
        String json = new Gson().toJson(new AddTimesReq(i, i2, i3));
        HttpUtils insatance = HttpUtils.getInsatance();
        insatance.post(addStatisticsTimes, json, new HttpCallback<BaseRes>("addTimes" + i3) {
            /* class com.androidx.p013lv.player.view.BrushVideoPlayer.C14038 */

            public void onLvSuccess(BaseRes baseRes) {
            }
        });
    }

    public void isPurVideo() {
        HttpUtils.getInsatance().cancelTag("isPurVideo");
        HttpUtils.getInsatance().get(UrlManager.getInsatance().isPurVideo(this.videoBean.getVideoId()), new HttpCallback<BaseRes<PurVideoBean>>("isPurVideo") {
            /* class com.androidx.p013lv.player.view.BrushVideoPlayer.C14049 */

            public void onLvSuccess(BaseRes<PurVideoBean> baseRes) {
                if (baseRes.getCode() == 200 && baseRes.getData().getVideoId() == BrushVideoPlayer.this.videoBean.getVideoId()) {
                    BrushVideoPlayer.this.videoBean.setCanWatch(true);
                    BrushVideoPlayer.this.videoBean.setBuy(baseRes.getData().isPurVideo());
                    if (BrushVideoPlayer.this.isShow && BrushVideoPlayer.this.videoBean.isBuy()) {
                        BrushVideoPlayer.this.onVideoResume();
                        BrushVideoPlayer.this.root_pay.setVisibility(8);
                        BrushVideoPlayer.this.isShow = false;
                    }
                }
            }
        });
    }

    /* access modifiers changed from: protected */
    @Override // p000a.shuyu.p005a.video.StandardGSYVideoPlayer
    public int getProgressDialogLayoutId() {
        return C1387R.C1392layout.video_player_progress_dialog;
    }

    public void loadCoverImage(String str) {
        if (this.videoBean.isAd()) {
            this.ivImg.setVisibility(0);
            if (TextUtils.isEmpty(this.videoBean.getVideoUrl())) {
                ((RequestBuilder) ((RequestBuilder) ((RequestBuilder) Glide.with(getContext()).load(str).centerCrop()).error(C1387R.C1389drawable.base_ic_default_cover)).placeholder(C1387R.C1389drawable.base_ic_default_cover)).into(this.ivImg);
                return;
            }
            this.ivImg.setImageDrawable(null);
            RequestManager with = Glide.with(getContext());
            ((RequestBuilder) ((RequestBuilder) ((RequestBuilder) with.load(str + "?m=2&w=" + 720 + "&h=" + 405).centerCrop()).error(C1387R.C1389drawable.base_ic_default_cover)).placeholder(C1387R.C1389drawable.base_ic_default_cover)).into(this.mCoverImage);
            return;
        }
        this.ivImg.setVisibility(8);
        RequestManager with2 = Glide.with(getContext());
        ((RequestBuilder) ((RequestBuilder) ((RequestBuilder) with2.load(str + "?m=2&w=" + 720 + "&h=" + 405).centerCrop()).error(C1387R.C1389drawable.base_ic_default_cover)).placeholder(C1387R.C1389drawable.base_ic_default_cover)).into(this.mCoverImage);
    }

    /* access modifiers changed from: protected */
    @Override // p000a.shuyu.p005a.video.StandardGSYVideoPlayer, p000a.shuyu.p005a.video.base.GSYVideoControlView
    public void changeUiToPreparingShow() {
        super.changeUiToPreparingShow();
        setViewShowState(this.mThumbImageViewLayout, 0);
        setViewShowState(this.view, 8);
    }

    public void onPlayerPause() {
        onVideoPause();
    }

    public int getProgress() {
        return this.mProgressBar.getProgress();
    }

    @Override // p000a.shuyu.p005a.video.base.GSYVideoControlView
    public void onProgressChanged(SeekBar seekBar, int i, boolean z) {
        super.onProgressChanged(seekBar, i, z);
        if (z) {
            this.mCurrentTimeTextView.setText(TimeUtils.stringForTime((long) ((i * getDuration()) / 100)));
        }
    }

    @Override // p000a.shuyu.p005a.video.base.GSYVideoView
    public void release() {
        super.release();
        Glide.with(this.mCoverImage.getContext()).clear(this.mCoverImage);
        Glide.with(this.ivImg.getContext()).clear(this.ivImg);
    }

    /* access modifiers changed from: protected */
    @Override // p000a.shuyu.p005a.video.base.GSYVideoControlView
    public void clickStartIcon() {
        super.clickStartIcon();
        LogUtils.m63e("ebdjs", getCurrentState() + "<----");
        if (!isIfCurrentIsFullscreen() && getCurrentState() != 5) {
            this.playerVideoInterface.click(this, this.videoBean, this.position, 1);
        }
        if (this.videoBean.getVideoType() == 2 && !this.videoBean.isBuy() && !this.videoBean.isCanWatch()) {
            isPurVideo();
        }
    }

    private void initVideoData() {
        VideoBean videoBean2 = this.videoBean;
        if (videoBean2 != null) {
            this.totalTimes.setText(TimeUtils.stringForTime(videoBean2.getPlayTime() * 1000));
            TextView textView = this.tv_lease_days;
            textView.setText(this.videoBean.getLeaseDays() + "");
            TextView textView2 = this.tv_lease_perice;
            textView2.setText(this.videoBean.getLeasePrice() + "");
            TextView textView3 = this.tv_buy_perice;
            textView3.setText(this.videoBean.getPrice() + "");
            if (this.videoBean.getCoverImg() == null || this.videoBean.getCoverImg().size() <= 0) {
                loadCoverImage(SpUtils.getInstance().getString("domain"));
            } else {
                loadCoverImage(SpUtils.getInstance().getString("domain") + this.videoBean.getCoverImg().get(0));
            }
            setUp(UrlManager.getInsatance().brushPlay(this.videoBean.getVideoUrl()), true, "");
            this.ivType.setVisibility(0);
            if (this.videoBean.getVideoType() == 1) {
                this.ivType.setImageResource(C1387R.C1389drawable.ic_vip);
                TextView textView4 = this.tvTitle;
                textView4.setText("           " + this.videoBean.getTitle());
            } else if (this.videoBean.getVideoType() == 2) {
                this.ivType.setImageResource(C1387R.C1389drawable.ic_pay);
                TextView textView5 = this.tvTitle;
                textView5.setText("          " + this.videoBean.getTitle());
            } else {
                this.ivType.setImageDrawable(null);
                this.tvTitle.setText(this.videoBean.getTitle());
            }
            this.mTopContainer.setVisibility(0);
        }
    }

    public void initTitle() {
        if (this.videoBean.getVideoType() == 1) {
            this.ivType.setImageResource(C1387R.C1389drawable.ic_vip);
            TextView textView = this.tvTitle;
            textView.setText("           " + this.videoBean.getTitle());
        } else if (this.videoBean.getVideoType() == 2) {
            this.ivType.setImageResource(C1387R.C1389drawable.ic_pay);
            TextView textView2 = this.tvTitle;
            textView2.setText("          " + this.videoBean.getTitle());
        } else {
            this.ivType.setImageDrawable(null);
            this.tvTitle.setText(this.videoBean.getTitle());
        }
        this.ivImg.setVisibility(8);
    }

    public VideoBean getVideoBean() {
        return this.videoBean;
    }

    public void setVideoBean(VideoBean videoBean2) {
        this.videoBean = videoBean2;
    }

    @Override // p000a.shuyu.p005a.video.base.GSYVideoControlView
    public int getEnlargeImageRes() {
        return C1387R.C1389drawable.player_brush_amplification;
    }

    @Override // p000a.shuyu.p005a.video.base.GSYVideoControlView
    public int getShrinkImageRes() {
        return C1387R.C1389drawable.player_brush_zoom_out;
    }
}
